<?php

/**
 * @version		$Id: hello.php 15 2009-11-02 18:37:15Z chdemko $
 * @package		Joomla16.Tutorials
 * @subpackage	Components
 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
 * @author		Christophe Demko
 * @link		http://joomlacode.org/gf/project/helloworld_1_6/
 * @license		License GNU General Public License version 2 or later
 */

/* No direct access to this file */
defined('_JEXEC') or die('Restricted access');

/* import Joomla modelitem library */
jimport('joomla.application.component.modelitem');


/* bgModelbg Model */
class bgModelbg extends JModel
{
    var $_total = null;
    var $_pagination = null;
    
    public function __construct(){
    	parent::__construct();
 
        $mainframe = JFactory::getApplication();
 
        /* Get pagination request variables */
        $limit = $mainframe->getUserStateFromRequest('com_information.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
        $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
 
        /* In case limit has been changed, adjust it */
        $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
 
        $this->setState('limit', $limit);
        $this->setState('limitstart', $limitstart);
    }
    
    /* get all records club */
	function getAll($list = null){

        $qr = "SELECT * FROM club";
        $where = array();
       /* search */
       
       if(isset($list['filter_search'])){
            $where[] = "CLUB_NAME LIKE '%$list[filter_search]%'";
       } 
       
       if($where){
            $where = ' WHERE '.implode(' AND ', $where);
        }else{
            $where = null;
        }
       /* get total number record */
       $this->_total = $this->getTotal($where);
       
       $qr .= $where;
       /* order by */
       $qr .= " ORDER BY CLUB_CODE DESC"; 
       
       /* pagination */
       $qr .= " LIMIT ".$this->getState('limitstart').",".$this->getState('limit');
       /* load data */
       $this->_db->setQuery($qr);
       $result = $this->_db->loadObjectList();
 
       return $result;
       
	}

    /* get total records */
    function getTotal($where = null){
        /* Load the content if it doesn't already exist */
        if ($this->_total === null) {
            $query = "SELECT count(*) FROM club $where";
            $this->_db->setQuery($query);
            $this->_total = $this->_db->loadResult();
        }
        return $this->_total;
    } 
    
    function getPagination(){
        /* Load the content if it doesn't already exist */
        if (empty($this->_pagination)) {
            jimport('joomla.html.pagination');
            $this->_pagination = new JPagination($this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
        }
        return $this->_pagination;
    }
    
    //Viet giong nhu the nay delete du lieu trong table cu roi insert du lieu moi tu file csv vao DB
    
    /* upload file csv */
    function uploadCSV($result){
        /* delete all records from club table */
        $query = "DELETE FROM club";
  
        $this->_db->setQuery($query);
        $this->_db->query();
        
        foreach($result as $key=>$row){
            /* skip first row */
            if($key == 0){
                continue;
            }
            /* insert values to club table */
            $qr = "INSERT INTO club (CLUB_CODE, CLUB_NAME, CLUB_FLAG) VALUES ('$row[0]', '$row[1]', '$row[2]')";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    
    
    /* remove club items */
    public function remove($cid){
        $cid = implode(',', $cid);
    
        $query = "DELETE FROM club WHERE CLUB_CODE IN($cid)";
  
        $this->_db->setQuery($query);
        $this->_db->query();
    }
    

    /**
    * copy images ocba
    */
    function update_daso_town(){
        ini_set('memory_limit', '1000M');
        $qr = "SELECT ACTT_CODE,ACTT_PERIOD_START,ACTT_PERIOD_FINISH FROM actt 
        WHERE ACTT_PERIOD_START = '0000-00-00' OR ACTT_PERIOD_FINISH = '0000-00-00'";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        foreach($result as $key=>$row){
            if ($row->ACTT_PERIOD_START == '0000-00-00') {
                $row->ACTT_PERIOD_START = NULL;
            }
            if ($row->ACTT_PERIOD_FINISH == '0000-00-00') {
                $row->ACTT_PERIOD_FINISH = NULL;
            }
            $qr = "UPDATE actt SET ACTT_PERIOD_START = '$row->ACTT_PERIOD_START'
                                    ,ACTT_PERIOD_FINISH = '$row->ACTT_PERIOD_FINISH'
                WHERE ACTT_CODE = $row->ACTT_CODE ";
            print_r($qr);die;
            $this->_db->setQuery($qr);
            $this->_db->query();
        }
    }

    //Day la upload table Town
    /**
	* upload file csv TOWN
	*/
    function uploadCSV_town($result){
        /*$this->_db->setQuery("DELETE FROM town");
        $this->_db->query();
        die;*/
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[0]=str_replace("\"","",$row[0]);
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $row[3]=str_replace("\"","",$row[3]);
            $row[4]=str_replace("\"","",$row[4]);
            $row[5]=str_replace("\"","",$row[5]);
            $row[6]=str_replace("\"","",$row[6]);
            $row[7]=str_replace("\"","",$row[7]);
            $row[8]=str_replace("\"","",$row[8]);
            $row[9]=str_replace("\"","",$row[9]);
            $row[10]=str_replace("\"","",$row[10]);
            $row[11]=str_replace("\"","",$row[11]);
            $row[12]=str_replace("\"","",$row[12]);
            $row[13]=str_replace("\"","",$row[13]);
            $row[14]=str_replace("\"","",$row[14]);
            $row[15]=str_replace("\"","",$row[15]);
            $row[16]=str_replace("\"","",$row[16]);
            $row[17]=str_replace("\"","",$row[17]);
            $row[18]=str_replace("\"","",$row[18]);
            $row[19]=str_replace("\"","",$row[19]);
            $row[20]=str_replace("\"","",$row[20]);
            $row[21]=str_replace("\"","",$row[21]);
            $row[22]=str_replace("\"","",$row[22]);
            $row[23]=str_replace("\"","",$row[23]);
            $row[24]=str_replace("\"","",$row[24]);
            $row[25]=str_replace("\"","",$row[25]);
            $row[26]=str_replace("\"","",$row[26]);
            $row[27]=str_replace("\"","",$row[27]);
            $row[28]=str_replace("\"","",$row[28]);
            $row[29]=str_replace("\"","",$row[29]);
            $row[30]=str_replace("\"","",$row[30]);
            $row[31]=str_replace("\"","",$row[31]);
            $row[32]=str_replace("\"","",$row[32]);
            $row[33]=str_replace("\"","",$row[33]);
            $row[34]=str_replace("\"","",$row[34]);
            $row[35]=str_replace("\"","",$row[35]);
            $row[36]=str_replace("\"","",$row[36]);
            $row[37]=str_replace("\"","",$row[37]);
            $row[38]=str_replace("\"","",$row[38]);
            $row[39]=str_replace("\"","",$row[39]);
            $qr = "INSERT INTO town 
                    (TOWN_CODE,TOWN_PREF_CODE,TOWN_NAME,TOWN_KANA
                    ,TOWN_POPU,TOWN_HOUS,TOWN_AREA,TOWN_DENS
                    ,TOWN_POST,TOWN_ADD1,TOWN_ADD2,TOWN_TEL
                    ,TOWN_FAX,TOWN_STAT,TOWN_MAIL,TOWN_HNAME
                    ,TOWN_HDATE,TOWN_DNAME,TOWN_ENAME,TOWN_EDATE
                    ,TOWN_UNIF,TOWN_SYM1,TOWN_SYM2,TOWN_SYM3
                    ,TOWN_SYM4,TOWN_NURS,TOWN_CHIL,TOWN_ELEM
                    ,TOWN_JUNI,TOWN_HIGH,TOWN_SIS1,TOWN_SIS2
                    ,TOWN_INDU,TOWN_DECL,TOWN_PR,TOWN_NOTE
                    ,TOWN_MURL,TOWN_URL,TOWN_CONT
                    ,TOWN_DATE,TOWN_FLAG,TOWN_WEBF,TOWN_USER_CREATE
                    ,TOWN_DBSY) 
                    VALUES 
                    ('$row[0]','$row[1]','$row[2]','$row[3]'
                    ,'$row[4]','$row[5]','$row[6]','$row[7]'
                    ,'$row[8]','$row[9]','$row[10]','$row[11]'
                    ,'$row[12]','$row[13]','$row[14]','$row[15]'
                    ,'$row[16]','$row[17]','$row[18]','$row[19]'
                    ,'$row[20]','$row[21]','$row[22]','$row[23]'
                    ,'$row[24]','$row[25]','$row[26]','$row[27]'
                    ,'$row[28]','$row[29]','$row[30]','$row[31]'
                    ,'$row[32]','$row[33]','$row[34]','$row[35]'
                    ,'$row[36]','$row[37]','$row[38]'
                    ,NOW(),1,'$row[39]',1
                    ,0)";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    
    //Table user
    /**
	* upload file csv USER
	*/
    function uploadCSV_user($result){
        //$this->_db->setQuery("DELETE FROM kc2vr_users");
        //$this->_db->query();
        
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $qr = "INSERT INTO kc2vr_users 
                    (id,username,name,email
                    ,USEM_OCBA_CODE
                    ,password
                    ,usertype,block,sendEmail,registerDate
                    ,lastvisitDate,activation,params,lastResetTime
                    ,resetCount) 
                    VALUES 
                    ($row[0],'$row[1]','$row[2]','$row[3]'
                    ,'$row[4]'
                    ,'b3480aad3549b0a95dfe11c977d95cca:4MW75FA9OQKq6AECRtikY9h5JGqqONHi'
                    ,'d','0','1',NOW()
                    ,NOW(),'d','d',NOW()
                    ,0)";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    
    /**
    * copy images ocba
    */
    function update_pass_user(){
        ini_set('memory_limit', '1000M');
        $qr = "SELECT id FROM kc2vr_users";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        foreach($result as $key=>$row){
            if($row->id != 1636 || $row->id != 1638 || $row->id != 1639 || $row->id != 1640 || $row->id != 1641 || $row->id != 1642){
                $qr = "UPDATE kc2vr_users SET password = '1f415c1c18871e91efcf93809b854ae0:QCVoY0z35UvBXBf4MQaXvtGvPQfokq6T'
                    WHERE id = $row->id";
                $this->_db->setQuery($qr);
                $this->_db->query();
            } 
        }
    }

    /**
	* upload file csv GROUP USER MAP
	*/
    function uploadCSV_group_user_map($result){
        //$this->_db->setQuery("DELETE FROM kc2vr_user_usergroup_map");
        //$this->_db->query();
        
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $qr = "INSERT INTO kc2vr_user_usergroup_map 
                    (user_id,group_id) 
                    VALUES 
                    ('$row[0]','$row[1]')";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    
    /**
    * copy images ocba
    */
    function replace_KT_DB(){
        ini_set('memory_limit', '1000M');
        $qr = "SELECT OCBA_PERI,OCBA_REST,OCBA_PR,OCBA_DADD1,OCBA_DADD2,OCBA_LADD1,OCBA_LADD2,OCBA_CODE FROM ocba";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        foreach($result as $key=>$row){
            $row->OCBA_PERI=str_replace(".",",",$row->OCBA_PERI);
            $row->OCBA_REST=str_replace(".",",",$row->OCBA_REST);
            $row->OCBA_PR=str_replace(".",",",$row->OCBA_PR);
            $row->OCBA_DADD1=str_replace(".",",",$row->OCBA_DADD1);
            $row->OCBA_DADD2=str_replace(".",",",$row->OCBA_DADD2);
            $row->OCBA_LADD1=str_replace(".",",",$row->OCBA_LADD1);
            $row->OCBA_LADD2=str_replace(".",",",$row->OCBA_LADD2);
            $qr = "UPDATE ocba SET OCBA_PERI = '$row->OCBA_PERI'
                                    ,OCBA_REST = '$row->OCBA_REST'
                                    ,OCBA_PR = '$row->OCBA_PR'
                                    ,OCBA_DADD1 = '$row->OCBA_DADD1'
                                    ,OCBA_DADD2 = '$row->OCBA_DADD2'
                                    ,OCBA_LADD1 = '$row->OCBA_LADD1'
                                    ,OCBA_LADD2 = '$row->OCBA_LADD2'
                WHERE OCBA_CODE = '$row->OCBA_CODE' ";
            $this->_db->setQuery($qr);
            $this->_db->query();
        }
    }

    /**
	* upload file csv OCBA
	*/
    function uploadCSV_ocba($result){
        /*$this->_db->setQuery("DELETE FROM ocba");
        $this->_db->query();
        die;*/
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $row[3]=str_replace("\"","",$row[3]);
            $row[4]=str_replace("\"","",$row[4]);
            $row[5]=str_replace("\"","",$row[5]);
            $row[6]=str_replace("\"","",$row[6]);
            $row[7]=str_replace("\"","",$row[7]);
            $row[8]=str_replace("\"","",$row[8]);
            $row[9]=str_replace("\"","",$row[9]);
            $row[10]=str_replace("\"","",$row[10]);
            $row[11]=str_replace("\"","",$row[11]);
            $row[12]=str_replace("\"","",$row[12]);
            $row[13]=str_replace("\"","",$row[13]);
            $row[14]=str_replace("\"","",$row[14]);
            $row[15]=str_replace("\"","",$row[15]);
            $row[16]=str_replace("\"","",$row[16]);
            $row[17]=str_replace("\"","",$row[17]);
            $row[18]=str_replace("\"","",$row[18]);
            $row[19]=str_replace("\"","",$row[19]);
            $row[20]=str_replace("\"","",$row[20]);
            $row[21]=str_replace("\"","",$row[21]);
            $row[22]=str_replace("\"","",$row[22]);
            $row[23]=str_replace("\"","",$row[23]);
            $row[24]=str_replace("\"","",$row[24]);
            $row[25]=str_replace("\"","",$row[25]);
            $row[26]=str_replace("\"","",$row[26]);
            $row[27]=str_replace("\"","",$row[27]);
            $row[28]=str_replace("\"","",$row[28]);
            $row[29]=str_replace("\"","",$row[29]);
            $row[30]=str_replace("\"","",$row[30]);
            $row[31]=str_replace("\"","",$row[31]);
            $row[32]=str_replace("\"","",$row[32]);
            $row[33]=str_replace("\"","",$row[33]);
            $row[34]=str_replace("\"","",$row[34]);
            $row[35]=str_replace("\"","",$row[35]);
            $row[36]=str_replace("\"","",$row[36]);
            $row[37]=str_replace("\"","",$row[37]);
            $row[38]=str_replace("\"","",$row[38]);
            $row[39]=str_replace("\"","",$row[39]);
            $row[40]=str_replace("\"","",$row[40]);
            $row[41]=str_replace("\"","",$row[41]);
            $row[42]=str_replace("\"","",$row[42]);
            $row[43]=str_replace("\"","",$row[43]);
            $row[44]=str_replace("\"","",$row[44]);
            $row[45]=str_replace("\"","",$row[45]);
            $row[46]=str_replace("\"","",$row[46]);
            $row[47]=str_replace("\"","",$row[47]);
            $row[48]=str_replace("\"","",$row[48]);
            $row[49]=str_replace("\"","",$row[49]);
            $row[50]=str_replace("\"","",$row[50]);
            $row[51]=str_replace("\"","",$row[51]);
            $row[52]=str_replace("\"","",$row[52]);
            $row[53]=str_replace("\"","",$row[53]);
            $row[54]=str_replace("\"","",$row[54]);
            $row[55]=str_replace("\"","",$row[55]);
            $row[56]=str_replace("\"","",$row[56]);
            $row[57]=str_replace("\"","",$row[57]);
            $row[58]=str_replace("\"","",$row[58]);
            $row[59]=str_replace("\"","",$row[59]);
            $row[60]=str_replace("\"","",$row[60]);
            $qr = "INSERT INTO ocba 
                    (OCBA_CODE,OCBA_NAME,OCBA_SHOR,OCBA_KANA
                    ,OCBA_TERM_CODE,OCBA_PETT_CODE,OCBA_CLUB_CODE,OCBA_TOWN_CODE
                    ,OCBA_CLUB_DEPEND,OCBA_SUPP,OCBA_POST,OCBA_ADD1
                    ,OCBA_ADD2,OCBA_TEL,OCBA_FAX,OCBA_LPOST
                    ,OCBA_LADD1,OCBA_LADD2,OCBA_LTEL,OCBA_LFAX
                    ,OCBA_LNAME,OCBA_DM,OCBA_DPOST,OCBA_DADD1
                    ,OCBA_DADD2,OCBA_DNAME,OCBA_YMAIL,OCBA_YNAME
                    ,OCBA_EMAIL,OCBA_ENAME,OCBA_TMAIL,OCBA_TNAME
                    ,OCBA_CMAIL,OCBA_CNAME,OCBA_OMAIL,OCBA_ONAME
                    ,OCBA_URL,OCBA_MURL,OCBA_HEAD,OCBA_CONT
                    ,OCBA_ENTR,OCBA_SDATE,OCBA_TDATE,OCBA_EDATE
                    ,OCBA_EFLAG,OCBA_STIME,OCBA_PERI,OCBA_REST
                    ,OCBA_PR,OCBA_IMG,OCBA_PUTF,OCBA_LARF
                    ,OCBA_CANF,OCBA_YACF,OCBA_SCHF,OCBA_OUTF
                    ,OCBA_DATE,OCBA_FLAG,OCBA_WEBF,OCBA_INST
                    ,OCBA_COMA_CODE,OCBA_CODT,OCBA_USER_CREATE,OCBA_DBSY
                    ,OCBA_LOAIHINH) 
                    VALUES 
                    ('$row[0]','$row[1]','$row[2]','$row[3]'
                    ,'$row[4]','$row[5]','$row[6]','$row[7]'
                    ,'$row[8]','$row[9]','$row[10]','$row[11]'
                    ,'$row[12]','$row[13]','$row[14]','$row[15]'
                    ,'$row[16]','$row[17]','$row[18]','$row[19]'
                    ,'$row[20]','$row[21]','$row[22]','$row[23]'
                    ,'$row[24]','$row[25]','$row[26]','$row[27]'
                    ,'$row[28]','$row[29]','$row[30]','$row[31]'
                    ,'$row[32]','$row[33]','$row[34]','$row[35]'
                    ,'$row[36]','$row[37]','$row[38]','$row[39]'
                    ,'$row[40]','$row[41]','$row[42]','$row[43]'
                    ,'$row[44]','$row[45]','$row[46]','$row[47]'
                    ,'$row[48]','$row[49]','$row[50]','$row[51]'
                    ,'$row[52]','$row[53]','$row[54]','$row[55]'
                    ,NOW(),1,'$row[60]','$row[56]'
                    ,'$row[57]','$row[58]',1,0
                    ,'$row[59]')";
            $this->_db->setQuery($qr);
            $this->_db->query();
            
         } 
    }
    
    /**
    * copy images ocba
    */
    function update_0(){
        ini_set('memory_limit', '1000M');
        $qr = "SELECT * FROM ocba";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        foreach($result as $key=>$row){
            if($row->OCBA_TERM_CODE == 0){
                $OCBA_TERM_CODE = 'NULL';
            }
            else{
                $OCBA_TERM_CODE = $row->OCBA_TERM_CODE;
            }
            if($row->OCBA_PETT_CODE == 0){
                $OCBA_PETT_CODE = 'NULL';
            }
            else{
                $OCBA_PETT_CODE = $row->OCBA_PETT_CODE;
            }
            if($row->OCBA_LOAIHINH == 0){
                $OCBA_LOAIHINH = 'NULL';
            }
            else{
                $OCBA_LOAIHINH = $row->OCBA_LOAIHINH;
            }
            if($row->OCBA_CLUB_CODE == 0){
                $OCBA_CLUB_CODE = 'NULL';
            }
            else{
                $OCBA_CLUB_CODE = $row->OCBA_CLUB_CODE;
            }
            $qr = "UPDATE ocba SET OCBA_TERM_CODE = $OCBA_TERM_CODE
                                    ,OCBA_PETT_CODE = $OCBA_PETT_CODE
                                    ,OCBA_LOAIHINH = $OCBA_LOAIHINH
                                    ,OCBA_CLUB_CODE = $OCBA_CLUB_CODE
                    WHERE OCBA_CODE = $row->OCBA_CODE";
                    //echo $qr;die;
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }

    /**
    * copy images ocba
    */
    function delete_row_gymt(){
        ini_set('memory_limit', '1000M');
        $qr = "SELECT * FROM gymt";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        foreach($result as $key=>$row){
            if($row->GYMT_SDATE == '0000-00-00 00:00:00' 
                && $row->GYMT_TDATE == '0000-00-00 00:00:00' 
                && $row->GYMT_EDATE == '0000-00-00 00:00:00'){
                $qr = "DELETE FROM gymt WHERE GYMT_CODE IN($row->GYMT_CODE)";
            $this->_db->setQuery($qr);
            $this->_db->query();
            } 
        }
    }
    /**
    * upload file update DOCK date
    */
    function update_town_danso($result){
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $qr = "UPDATE town SET TOWN_AREA = '$row[1]'
                                    ,TOWN_DENS = '$row[2]'
                    WHERE TOWN_CODE = '$row[0]'";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    /**
	* upload file update DOCK date
	*/
    function update_dock_date($result){
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $qr = "UPDATE dock SET DOCK_SDATE = '$row[1]'
                                    ,DOCK_TDATE = '$row[2]'
                    WHERE TOWN_CODE = '$row[0]'";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }

    /**
    * upload file update DOCK date
    */
    function update_pool_20131028($result){
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[0]=str_replace("\"","",$row[0]);
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $qr = "UPDATE pool SET POOL_ADMN = '$row[1]'
                                    ,POOL_NOTE = '$row[2]'
                    WHERE POOL_OCBA_CODE = '$row[0]'";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }

    /**
    * upload file update DOCK date
    */
    function update_dock_20131025($result){
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $row[3]=str_replace("\"","",$row[3]);
            $row[4]=str_replace("\"","",$row[4]);
            $row[5]=str_replace("\"","",$row[5]);
            $row[6]=str_replace("\"","",$row[6]);
            $row[7]=str_replace("\"","",$row[7]);
            $qr = "UPDATE dock SET DOCK_ADD1 = '$row[1]'
                                    ,DOCK_TERM = '$row[2]'
                                    ,DOCK_ADMN = '$row[3]'
                                    ,DOCK_CNOT = '$row[4]'
                                    ,DOCK_NOTE = '$row[5]'
                                    ,DOCK_WNAME = '$row[6]'
                                    ,DOCK_WNAMEW = '$row[7]'
                    WHERE DOCK_OCBA_CODE = '$row[0]'";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }

    /**
    * upload file update DOCK date
    */
    function update_ocba_20131025($result){
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[1]=str_replace("\"","",$row[1]);
            $qr = "UPDATE ocba SET OCBA_REST = '$row[1]'
                    WHERE OCBA_CODE = '$row[0]'";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    
    /**
	* upload file update OCBA_PR
	*/
    function update_ocba_pr($result){
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $qr = "UPDATE ocba SET OCBA_PR = '$row[1]'
                    WHERE OCBA_CODE = '$row[0]'";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    
    /**
	* upload file update OCBA_REST
	*/
    function update_ocba_rest($result){
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $qr = "UPDATE ocba SET OCBA_REST = '$row[1]'
                    WHERE OCBA_CODE = '$row[0]'";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    
    /**
	* upload file update OCBA_COMA_CODE
	*/
    function update_ocba($result){
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $qr = "UPDATE ocba SET OCBA_COMA_CODE = '$row[1]'
                    WHERE OCBA_CODE = '$row[0]'";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    
    /**
	* upload file update images ocba
	*/
    function update_ocba_images($result){
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $qr = "UPDATE ocba SET OCBA_IMG = '$row[1]'
                    WHERE OCBA_CODE = '$row[0]'";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    
     /**
    * upload file update images ocba
    */
    function update_actt_webf($result){
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $qr = "UPDATE actt SET ACTT_WEBF = '$row[1]'
                    WHERE ACTT_CODE = '$row[0]'";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }

    /**
    * copy images ocba
    */
    /*function copy_ocba_images($result){
        ini_set('memory_limit', '1000M');
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[0]=str_replace("\"","",$row[0]);
            $row[1]=str_replace("\"","",$row[1]);
        //$pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\com_center';
        $srcfile= "$row[1]";
        $dstfile= "$pathDest\\$row[0]";
        copy($srcfile, $dstfile);
        } 
    }*/

    /**
	* copy images ocba
	*/
    function copy_ocba_images(){
        ini_set('memory_limit', '1000M');
        $qr = "SELECT OCBA_CODE,OCBA_IMG FROM ocba";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\com_center';
        foreach($result as $row){
            if ($row->OCBA_IMG != '') {
                $srcfile= "$pathSource\\$row->OCBA_CODE\\$row->OCBA_IMG";
                $dstfile= "$pathDest\\$row->OCBA_IMG";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->OCBA_CODE ---- $row->OCBA_IMG ...\n";
                }
            }
        } 
    }
    
    /**
	* copy images dock_1
	*/
    function copy_dock_1_images(){
        $qr = "SELECT DOCK_OCBA_CODE,DOCK_IMGD FROM dock";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\com_pgb';
        foreach($result as $row){
            if ($row->DOCK_IMGD != '') {
                $srcfile= "$pathSource\\$row->DOCK_OCBA_CODE\\$row->DOCK_IMGD";
                $dstfile= "$pathDest\\$row->DOCK_IMGD";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->DOCK_OCBA_CODE ---- $row->DOCK_IMGD ...\n";
                }
            }
        } 
    }
    
    /**
	* copy images dock_2
	*/
    function copy_dock_2_images(){
        $qr = "SELECT DOCK_OCBA_CODE,DOCK_IMGW FROM dock";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\com_pgb'; 
        foreach($result as $row){
            if ($row->DOCK_IMGW != '') {
                $srcfile= "$pathSource\\$row->DOCK_OCBA_CODE\\$row->DOCK_IMGW";
                $dstfile= "$pathDest\\$row->DOCK_IMGW";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->DOCK_OCBA_CODE ---- $row->DOCK_IMGW ...\n";
                }
            }
        }
    }
    
    /**
	* copy images dock_3
	*/
    function copy_dock_3_images(){
        $qr = "SELECT DOCK_OCBA_CODE,DOCK_IMGS FROM dock";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\com_pgb';
        foreach($result as $row){
            if ($row->DOCK_IMGS != '') {
                $srcfile= "$pathSource\\$row->DOCK_OCBA_CODE\\$row->DOCK_IMGS";
                $dstfile= "$pathDest\\$row->DOCK_IMGS";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->DOCK_OCBA_CODE ---- $row->DOCK_IMGS ...\n";
                }
            }
        }
    }
    
    /**
	* copy images actt_1
	*/
    function copy_actt_1_images(){
        $qr = "SELECT ACTT_OCBA_CODE,ACTT_IMAGE_1 FROM actt";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\com_activity';
        foreach($result as $row){
            if ($row->ACTT_IMAGE_1 != '') {
                $srcfile= "$pathSource\\$row->ACTT_OCBA_CODE\\$row->ACTT_IMAGE_1";
                $dstfile= "$pathDest\\$row->ACTT_IMAGE_1";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->ACTT_OCBA_CODE ---- $row->ACTT_IMAGE_1 ...\n";
                }
            }
        }
    }
    
    /**
	* copy images actt_2
	*/
    function copy_actt_2_images(){
        $qr = "SELECT ACTT_OCBA_CODE,ACTT_IMAGE_2 FROM actt";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\com_activity';
        foreach($result as $row){
            if ($row->ACTT_IMAGE_2 != '') {
                $srcfile= "$pathSource\\$row->ACTT_OCBA_CODE\\$row->ACTT_IMAGE_2";
                $dstfile= "$pathDest\\$row->ACTT_IMAGE_2";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->ACTT_OCBA_CODE ---- $row->ACTT_IMAGE_2 ...\n";
                }
            }
        }
    }
    
    /**
	* copy images actt_3
	*/
    function copy_actt_3_images(){
        $qr = "SELECT ACTT_OCBA_CODE,ACTT_IMAGE_3 FROM actt";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\com_activity';
        foreach($result as $row){
            if ($row->ACTT_IMAGE_3 != '') {
                $srcfile= "$pathSource\\$row->ACTT_OCBA_CODE\\$row->ACTT_IMAGE_3";
                $dstfile= "$pathDest\\$row->ACTT_IMAGE_3";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->ACTT_OCBA_CODE ---- $row->ACTT_IMAGE_3 ...\n";
                }
            }
        } 
    }
    
    /**
	* copy images actt_4
	*/
    function copy_actt_4_images(){
        $qr = "SELECT ACTT_OCBA_CODE,ACTT_IMAGE_4 FROM actt";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\com_activity'; 
        foreach($result as $row){
            if ($row->ACTT_IMAGE_4 != '') {
                $srcfile= "$pathSource\\$row->ACTT_OCBA_CODE\\$row->ACTT_IMAGE_4";
                $dstfile= "$pathDest\\$row->ACTT_IMAGE_4";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->ACTT_OCBA_CODE ---- $row->ACTT_IMAGE_4 ...\n";
                }
            }
        }
    }
    
    /**
	* copy images actt_5
	*/
    function copy_actt_5_images(){
        $qr = "SELECT ACTT_OCBA_CODE,ACTT_IMAGE_5 FROM actt";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\com_activity';
        foreach($result as $row){
            if ($row->ACTT_IMAGE_5 != '') {
                $srcfile= "$pathSource\\$row->ACTT_OCBA_CODE\\$row->ACTT_IMAGE_5";
                $dstfile= "$pathDest\\$row->ACTT_IMAGE_5";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->ACTT_OCBA_CODE ---- $row->ACTT_IMAGE_5 ...\n";
                }
            }
        }
    }
    
    /**
	* copy file actt_1
	*/
    function copy_actt_1_file(){
        $qr = "SELECT ACTT_OCBA_CODE,ACTT_ATTACHMENT_1 FROM actt";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\files\com_activity';
        foreach($result as $row){
            if ($row->ACTT_ATTACHMENT_1 != '') {
                $srcfile= "$pathSource\\$row->ACTT_OCBA_CODE\\$row->ACTT_ATTACHMENT_1";
                $dstfile= "$pathDest\\$row->ACTT_ATTACHMENT_1";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->ACTT_OCBA_CODE ---- $row->ACTT_ATTACHMENT_1 ...\n";
                }
            }
        }
    }
    
    /**
	* copy file actt_2
	*/
    function copy_actt_2_file(){
        $qr = "SELECT ACTT_OCBA_CODE,ACTT_ATTACHMENT_2 FROM actt";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\files\com_activity';
        foreach($result as $row){
            if ($row->ACTT_ATTACHMENT_2 != '') {
                $srcfile= "$pathSource\\$row->ACTT_OCBA_CODE\\$row->ACTT_ATTACHMENT_2";
                $dstfile= "$pathDest\\$row->ACTT_ATTACHMENT_2";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->ACTT_OCBA_CODE ---- $row->ACTT_ATTACHMENT_2 ...\n";
                }
            }
        }
    }
    
    /**
	* copy file actt_3
	*/
    function copy_actt_3_file(){
        $qr = "SELECT ACTT_OCBA_CODE,ACTT_ATTACHMENT_3 FROM actt";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\files\com_activity';
        foreach($result as $row){
            if ($row->ACTT_ATTACHMENT_3 != '') {
                $srcfile= "$pathSource\\$row->ACTT_OCBA_CODE\\$row->ACTT_ATTACHMENT_3";
                $dstfile= "$pathDest\\$row->ACTT_ATTACHMENT_3";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->ACTT_OCBA_CODE ---- $row->ACTT_ATTACHMENT_3 ...\n";
                }
            }
        }
    }
    
    /**
	* copy file actt_4
	*/
    function copy_actt_4_file(){
        $qr = "SELECT ACTT_OCBA_CODE,ACTT_ATTACHMENT_4 FROM actt";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\files\com_activity'; 
        foreach($result as $row){
            if ($row->ACTT_ATTACHMENT_4 != '') {
                $srcfile= "$pathSource\\$row->ACTT_OCBA_CODE\\$row->ACTT_ATTACHMENT_4";
                $dstfile= "$pathDest\\$row->ACTT_ATTACHMENT_4";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->ACTT_OCBA_CODE ---- $row->ACTT_ATTACHMENT_4 ...\n";
                }
            }
        }
    }
    
    /**
	* copy file actt_5
	*/
    function copy_actt_5_file(){
        $qr = "SELECT ACTT_OCBA_CODE,ACTT_ATTACHMENT_5 FROM actt";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\files\com_activity';
        foreach($result as $row){
            if ($row->ACTT_ATTACHMENT_5 != '') {
                $srcfile= "$pathSource\\$row->ACTT_OCBA_CODE\\$row->ACTT_ATTACHMENT_5";
                $dstfile= "$pathDest\\$row->ACTT_ATTACHMENT_5";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->ACTT_OCBA_CODE ---- $row->ACTT_ATTACHMENT_5 ...\n";
                }
            }
        }
    }
    
    /**
	* copy file actt_6
	*/
    function copy_actt_6_file(){
        $qr = "SELECT ACTT_OCBA_CODE,ACTT_ATTACHMENT_6 FROM actt";
        $this->_db->setQuery($qr);
        $result = $this->_db->loadObjectList();
        $pathSource = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\images\temp';
        $pathDest = 'C:\AppServ\www\V2SoftBNGINJOOM1306_1.4\administrator\uploads\files\com_activity';
        foreach($result as $row){
            if ($row->ACTT_ATTACHMENT_6 != '') {
                $srcfile= "$pathSource\\$row->ACTT_OCBA_CODE\\$row->ACTT_ATTACHMENT_6";
                $dstfile= "$pathDest\\$row->ACTT_ATTACHMENT_6";
                if (!copy($srcfile, $dstfile)) {
                    echo "failed to copy $row->ACTT_OCBA_CODE ---- $row->ACTT_ATTACHMENT_6 ...\n";
                }
            }
        }
    }
    
    /**
	* upload file csv GYMT
	*/
    function uploadCSV_gymt($result){
        // $this->_db->setQuery("DELETE FROM gymt");
        // $this->_db->query();
        // die;
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $row[3]=str_replace("\"","",$row[3]);
            $row[4]=str_replace("\"","",$row[4]);
            $row[5]=str_replace("\"","",$row[5]);
            $row[6]=str_replace("\"","",$row[6]);
            $row[7]=str_replace("\"","",$row[7]);
            $row[8]=str_replace("\"","",$row[8]);
            $row[9]=str_replace("\"","",$row[9]);
            $row[10]=str_replace("\"","",$row[10]);
            $row[11]=str_replace("\"","",$row[11]);
            $row[12]=str_replace("\"","",$row[12]);
            $row[13]=str_replace("\"","",$row[13]);
            $row[14]=str_replace("\"","",$row[14]);
            $row[15]=str_replace("\"","",$row[15]);
            $row[16]=str_replace("\"","",$row[16]);
            $qr = "INSERT INTO gymt 
                    (GYMT_CODE,GYMT_OCBA_CODE,GYMT_2NDK,GYMT_METK
                    ,GYMT_TBGY_CODE_LIST,GYMT_MATF,GYMT_MACF,GYMT_CIAD
                    ,GYMT_CICI,GYMT_COAD,GYMT_COCI,GYMT_CNOT
                    ,GYMT_SDATE,GYMT_TDATE,GYMT_EDATE,GYMT_ADMN
                    ,GYMT_NOTE
                    ,GYMT_DATE,GYMT_FLAG,GYMT_WEBF,GYMT_USER_CREATE) 
                    VALUES 
                    ('$row[0]','$row[1]','$row[2]','$row[3]'
                    ,'$row[4]','$row[5]','$row[6]','$row[7]'
                    ,'$row[8]','$row[9]','$row[10]','$row[11]'
                    ,'$row[12]','$row[13]','$row[14]','$row[15]'
                    ,'$row[16]'
                    ,NOW(),1,1,1)";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    
    /**
	* upload file csv POOL
	*/
    function uploadCSV_pool($result){
        /*$this->_db->setQuery("DELETE FROM pool");
        $this->_db->query();*/
        
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $row[3]=str_replace("\"","",$row[3]);
            $row[4]=str_replace("\"","",$row[4]);
            $row[5]=str_replace("\"","",$row[5]);
            $row[6]=str_replace("\"","",$row[6]);
            $row[7]=str_replace("\"","",$row[7]);
            $row[8]=str_replace("\"","",$row[8]);
            $row[9]=str_replace("\"","",$row[9]);
            $row[10]=str_replace("\"","",$row[10]);
            $row[11]=str_replace("\"","",$row[11]);
            $row[12]=str_replace("\"","",$row[12]);
            $row[13]=str_replace("\"","",$row[13]);
            $row[14]=str_replace("\"","",$row[14]);
            $row[15]=str_replace("\"","",$row[15]);
            $row[16]=str_replace("\"","",$row[16]);
            $row[17]=str_replace("\"","",$row[17]);
            $qr = "INSERT INTO pool 
                    (POOL_CODE,POOL_OCBA_CODE,POOL_POLK,POOL_POHK
                    ,POOL_TERM,POOL_TBPO_CODE_LIST,POOL_DISP_CODE_LIST,POOL_CIAD
                    ,POOL_CICI,POOL_COAD,POOL_COCI,POOL_CNOT
                    ,POOL_METK,POOL_SDATE,POOL_TDATE,POOL_EDATE
                    ,POOL_ADMN,POOL_NOTE
                    ,POOL_DATE,POOL_FLAG,POOL_WEBF,POOL_USER_CREATE) 
                    VALUES 
                    ('$row[0]','$row[1]','$row[2]','$row[3]'
                    ,'$row[4]','$row[5]','$row[6]','$row[7]'
                    ,'$row[8]','$row[9]','$row[10]','$row[11]'
                    ,'$row[12]','$row[13]','$row[14]','$row[15]'
                    ,'$row[16]','$row[17]'
                    ,NOW(),1,1,1)";
            $this->_db->setQuery($qr);
            if (!$this->_db->query()) {
                echo "<meta charset='UTF-8' />";
                print_r($qr);
            }
         } 
    }
    
    /**
	* upload file csv DOCK
	*/
    function uploadCSV_dock($result){
        //$this->_db->setQuery("DELETE FROM dock"); //Chu y update thi ko xoa
        //$this->_db->query();
        
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $row[3]=str_replace("\"","",$row[3]);
            $row[4]=str_replace("\"","",$row[4]);
            $row[5]=str_replace("\"","",$row[5]);
            $row[6]=str_replace("\"","",$row[6]);
            $row[7]=str_replace("\"","",$row[7]);
            $row[8]=str_replace("\"","",$row[8]);
            $row[9]=str_replace("\"","",$row[9]);
            $row[10]=str_replace("\"","",$row[10]);
            $row[11]=str_replace("\"","",$row[11]);
            $row[12]=str_replace("\"","",$row[12]);
            $row[13]=str_replace("\"","",$row[13]);
            $row[14]=str_replace("\"","",$row[14]);
            $row[15]=str_replace("\"","",$row[15]);
            $row[16]=str_replace("\"","",$row[16]);
            $row[17]=str_replace("\"","",$row[17]);
            $row[18]=str_replace("\"","",$row[18]);
            $row[19]=str_replace("\"","",$row[19]);
            $row[20]=str_replace("\"","",$row[20]);
            $row[21]=str_replace("\"","",$row[21]);
            $row[22]=str_replace("\"","",$row[22]);
            $row[23]=str_replace("\"","",$row[23]);
            $row[24]=str_replace("\"","",$row[24]);
            $row[25]=str_replace("\"","",$row[25]);
            $row[26]=str_replace("\"","",$row[26]);
            $row[27]=str_replace("\"","",$row[27]);
            $row[28]=str_replace("\"","",$row[28]);
            $row[29]=str_replace("\"","",$row[29]);
            $row[30]=str_replace("\"","",$row[30]);
            $row[31]=str_replace("\"","",$row[31]);
            $row[32]=str_replace("\"","",$row[32]);
            $row[33]=str_replace("\"","",$row[33]);
            $qr = "INSERT INTO dock 
                    (DOCK_CODE,DOCK_OCBA_CODE,DOCK_DOCM_CODE,DOCK_WATM_CODE
                    ,DOCK_POST,DOCK_ADD1,DOCK_TEL,DOCK_FAX
                    ,DOCK_TERM,DOCK_WNAME,DOCK_WNAMEW,DOCK_WNOTE
                    ,DOCK_TOYK,DOCK_SHWK,DOCK_SHHK,DOCK_CHAK
                    ,DOCK_PAKK,DOCK_TBDO_CODE_LIST,DOCK_FTMF,DOCK_DOWM_CODE
                    ,DOCK_SDATE,DOCK_TDATE,DOCK_EDATE,DOCK_ADMN
                    ,DOCK_CIAD,DOCK_CICI,DOCK_COAD,DOCK_COCI
                    ,DOCK_CNOT,DOCK_IMGD,DOCK_IMGW,DOCK_IMGS
                    ,DOCK_NOTE,DOCK_RSVF
                    ,DOCK_DATE,DOCK_FLAG,DOCK_WEBF,DOCK_USER_CREATE) 
                    VALUES 
                    ('$row[0]','$row[1]','$row[2]','$row[3]'
                    ,'$row[4]','$row[5]','$row[6]','$row[7]'
                    ,'$row[8]','$row[9]','$row[10]','$row[11]'
                    ,'$row[12]','$row[13]','$row[14]','$row[15]'
                    ,'$row[16]','$row[17]','$row[18]','$row[19]'
                    ,'$row[20]','$row[21]','$row[22]','$row[23]'
                    ,'$row[24]','$row[25]','$row[26]','$row[27]'
                    ,'$row[28]','$row[29]','$row[30]','$row[31]'
                    ,'$row[32]','$row[33]'
                    ,NOW(),1,1,1)";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    /**
	* upload file csv COLI
	*/
    function uploadCSV_coli($result){
        /*$this->_db->setQuery("DELETE FROM coli");
        $this->_db->query();*/
        
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $row[3]=str_replace("\"","",$row[3]);
            $row[4]=str_replace("\"","",$row[4]);
            $row[5]=str_replace("\"","",$row[5]);
            $row[6]=str_replace("\"","",$row[6]);
            $row[7]=str_replace("\"","",$row[7]);
            $row[8]=str_replace("\"","",$row[8]);
            $row[9]=str_replace("\"","",$row[9]);
            $qr = "INSERT INTO coli 
                    (COLI_CODE,COLI_COCH_CODE,COLI_COCM_CODE,COLI_COTF
                    ,COLI_OCBA_CODE,COLI_TERM,COLI_UNIT,COLI_JDATE
                    ,COLI_OLDF,COLI_NOTE
                    ,COLI_DATE,COLI_USER_CREATE) 
                    VALUES 
                    ('$row[0]','$row[1]','$row[2]','$row[3]'
                    ,'$row[4]','$row[5]','$row[6]','$row[7]'
                    ,'$row[8]','$row[9]'
                    ,NOW(),1)";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    /**
	* upload file csv COLI
	*/
    function uploadCSV_term($result){
        /*$this->_db->setQuery("DELETE FROM term");
        $this->_db->query();*/
        
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $row[3]=str_replace("\"","",$row[3]);
            $qr = "INSERT INTO term 
                    (TERM_CODE,TERM_YEAR,TERM_NAME,TERM_FLAG) 
                    VALUES 
                    ('$row[0]','$row[1]','$row[2]','$row[3]')";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    /**
	* upload file csv USCE
	*/
    function uploadCSV_usce($result){
        set_time_limit(1800);
        //$this->_db->setQuery("DELETE FROM usce");
//        $this->_db->query();
        
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }            
            $qr = "INSERT INTO usce 
                    (USCE_CODE,USCE_OCBA_CODE,USCE_DATE,USCE_USCM_CODE
                    ,USCE_USFM_CODE,USCE_VAL
                    ,USCE_UPDATE) 
                    VALUES 
                    ('$row[0]','$row[1]','$row[2]','$row[3]'
                    ,'$row[4]','$row[5]'
                    ,NOW())";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }
    /**
	* upload file csv USCL
	*/
    function uploadCSV_uscl($result){
        set_time_limit(1800);
        
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }            
            $qr = "INSERT INTO uscl 
                    (USCL_CODE,USCL_OCBA_CODE,USCL_DATE,USCL_PACM_CODE
                    ,USCL_ACTM_CODE,USCL_VAL
                    ,USCL_UPDATE) 
                    VALUES 
                    ('$row[0]','$row[1]','$row[2]','$row[3]'
                    ,'$row[4]','$row[5]'
                    ,NOW())";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }

    /**
    * upload file csv USCL
    */
    function uploadCSV_uscl_check_trung($result){
        set_time_limit(1800);
        
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }            
            $qr = "SELECT USCL_CODE FROM uscl 
                    WHERE USCL_CODE = $row[0]";

            $this->_db->setQuery($qr);
            $result = $this->_db->loadObject();
            if (empty($result)) {
                print_r($row[0]);
                echo "<br />";
            }
         } 
    }

    /**
    * upload file csv USCL
    */
    function uploadCSV_uscl_check_khac($result){
        set_time_limit(1800);
        
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }      
            //Check dòng mới thêm vào     
            $qr = "SELECT * FROM uscl 
                    WHERE USCL_OCBA_CODE = '$row[1]' && USCL_DATE = '$row[2]' 
                    && USCL_PACM_CODE = '$row[3]' && USCL_ACTM_CODE = '$row[4]'";
            $this->_db->setQuery($qr);
            $result = $this->_db->loadObject();
            if (empty($result)) {
                echo 'them_' . $row[0];
                //print_r($row[0]);
                echo "<br />";
            }
            //Check dòng bị sửa
            $qr1 = "SELECT * FROM uscl 
                    WHERE USCL_OCBA_CODE = '$row[1]' && USCL_DATE = '$row[2]' 
                    && USCL_PACM_CODE = '$row[3]' && USCL_ACTM_CODE = '$row[4]' && USCL_VAL != '$row[5]'";
            $this->_db->setQuery($qr1);
            $result1 = $this->_db->loadObject();
            if (!empty($result1)) {
                echo 'edit_values_' . $row[0];
                //print_r($row[0]);
                echo "<br />";
            }
         } 
    }

    //check null id
    function check_null_COCH_CODE($result){
        foreach ($result as $key => $row) {
            if ($key == 0) {
                continue;
            }
            $qr = "SELECT * FROM pool WHERE POOL_CODE = '$row[0]'";
            $this->_db->setQuery($qr);
            $array = $this->_db->loadObject();
            if (empty($array)) {
                echo $row[0] . '<br />';
            }
        }
    }

    /**
	* upload file csv COCH
	*/
    function uploadCSV_coch($result){
        /*$this->_db->setQuery("DELETE FROM coch");
        $this->_db->query();
        die;*/
        
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $row[3]=str_replace("\"","",$row[3]);
            $row[4]=str_replace("\"","",$row[4]);
            $row[5]=str_replace("\"","",$row[5]);
            $row[6]=str_replace("\"","",$row[6]);
            $row[7]=str_replace("\"","",$row[7]);
            $row[8]=str_replace("\"","",$row[8]);
            $row[9]=str_replace("\"","",$row[9]);
            $row[10]=str_replace("\"","",$row[10]);
            $row[11]=str_replace("\"","",$row[11]);
            $row[12]=str_replace("\"","",$row[12]);
            $row[13]=str_replace("\"","",$row[13]);
            $row[14]=str_replace("\"","",$row[14]);
            $row[15]=str_replace("\"","",$row[15]);
            $row[16]=str_replace("\"","",$row[16]);
            $row[17]=str_replace("\"","",$row[17]);
            $row[18]=str_replace("\"","",$row[18]);
            $row[19]=str_replace("\"","",$row[19]);
            $row[20]=str_replace("\"","",$row[20]);
            $row[21]=str_replace("\"","",$row[21]);
            $row[22]=str_replace("\"","",$row[22]);
            $row[23]=str_replace("\"","",$row[23]);
            $qr = "INSERT INTO coch 
                    (COCH_CODE,COCH_CD,COCH_OCBA_CODE,COCH_JOBM_CODE
                    ,COCH_NAME,COCH_KANA,COCH_SEX,COCH_BDATE
                    ,COCH_POST,COCH_ADD1,COCH_TEL,COCH_FAX
                    ,COCH_MAIL,COCH_UNIT,COCH_POSI,COCH_WOKF
                    ,COCH_IMG,COCH_RDATE,COCH_MDATE,COCH_LDATE
                    ,COCH_EDATE,COCH_DDATE,COCH_COMM,COCH_NOTE
                    ,COCH_DATE
                    ) 
                    VALUES 
                    ('$row[0]','$row[1]','$row[2]','$row[3]'
                    ,'$row[4]','$row[5]','$row[6]','$row[7]'
                    ,'$row[8]','$row[9]','$row[10]','$row[11]'
                    ,'$row[12]','$row[13]','$row[14]','$row[15]'
                    ,'$row[16]','$row[17]','$row[18]','$row[19]'
                    ,'$row[20]','$row[21]','$row[22]','$row[23]'
                    ,NOW()
                    )";
            $this->_db->setQuery($qr);
            $this->_db->query();
         } 
    }

    //check null id
    function check_null_ACTT_CODE($result){
        foreach ($result as $key => $row) {
            if ($key == 0) {
                continue;
            }
            $qr = "SELECT * FROM actt WHERE ACTT_CODE = '$row[0]'";
            $this->_db->setQuery($qr);
            $array = $this->_db->loadObject();
            if (empty($array)) {
                echo $row[0] . '<br />';
            }
        }
    }

    /**
	* upload file csv ACTT
	*/
    function uploadCSV_actt($result){
        /*$this->_db->setQuery("DELETE FROM actt");
        $this->_db->query();
        die;*/
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $row[3]=str_replace("\"","",$row[3]);
            $row[4]=str_replace("\"","",$row[4]);
            $row[5]=str_replace("\"","",$row[5]);
            $row[6]=str_replace("\"","",$row[6]);
            $row[7]=str_replace("\"","",$row[7]);
            $row[8]=str_replace("\"","",$row[8]);
            $row[9]=str_replace("\"","",$row[9]);
            $row[10]=str_replace("\"","",$row[10]);
            $row[11]=str_replace("\"","",$row[11]);
            $row[12]=str_replace("\"","",$row[12]);
            $row[13]=str_replace("\"","",$row[13]);
            $row[14]=str_replace("\"","",$row[14]);
            $row[15]=str_replace("\"","",$row[15]);
            $row[16]=str_replace("\"","",$row[16]);
            $row[17]=str_replace("\"","",$row[17]);
            $row[18]=str_replace("\"","",$row[18]);
            $row[19]=str_replace("\"","",$row[19]);
            $row[20]=str_replace("\"","",$row[20]);
            $row[21]=str_replace("\"","",$row[21]);
            $row[22]=str_replace("\"","",$row[22]);
            $row[23]=str_replace("\"","",$row[23]);
            $row[24]=str_replace("\"","",$row[24]);
            $qr = "INSERT INTO actt 
                    (ACTT_CODE,ACTT_NAME,ACTT_RECOMMENDED_DEGREE,ACTT_OCBA_CODE
                    ,ACTT_PERIOD_START,ACTT_PERIOD_FINISH,ACTT_RECR,ACTT_VENUE
                    ,ACTT_TOCHUC,ACTT_TAITRO,ACTT_COOPERATION,ACTT_CONTACT
                    ,ACTT_PERSON,ACTT_TEL,ACTT_EFFECT,ACTT_TARGET
                    ,ACTT_SEX,ACTT_NUMBER_OF_PARTICIPANTS,ACTT_ENTRY_FEE,ACTT_TOTAL_PROJECT_COST
                    ,ACTT_BUSINESS,ACTT_REMARKS,ACTT_MFAC_CODE_LIST,ACTT_MOBJ_CODE_LIST
                    ,ACTT_MCON_CODE_LIST
                    ,ACTT_DATE,ACTT_WEBF,ACTT_FLAG,ACTT_USER_CREATE
                    ,ACTT_DBSY) 
                    VALUES 
                    ('$row[0]','$row[1]','$row[2]','$row[3]'
                    ,'$row[4]','$row[5]','$row[6]','$row[7]'
                    ,'$row[8]','$row[9]','$row[10]','$row[11]'
                    ,'$row[12]','$row[13]','$row[14]','$row[15]'
                    ,'$row[16]','$row[17]','$row[18]','$row[19]'
                    ,'$row[20]','$row[21]','$row[22]','$row[23]'
                    ,'$row[24]'
                    ,NOW(),1,1,1
                    ,0)";
            $this->_db->setQuery($qr);
            echo "<br/><br/>";
            if (!$this->_db->query()) {
                echo "<meta charset='UTF-8' />";
                print_r($qr);
            }
         } 
    }

    
    function update_actt_phan_2($result){
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
            $row[1]=str_replace("\"","",$row[1]);
            $row[2]=str_replace("\"","",$row[2]);
            $row[3]=str_replace("\"","",$row[3]);
            $row[4]=str_replace("\"","",$row[4]);
            $row[5]=str_replace("\"","",$row[5]);
            $row[6]=str_replace("\"","",$row[6]);
            $row[7]=str_replace("\"","",$row[7]);
            $row[8]=str_replace("\"","",$row[8]);
            $row[9]=str_replace("\"","",$row[9]);
            $row[10]=str_replace("\"","",$row[10]);
            $row[11]=str_replace("\"","",$row[11]);
            $row[12]=str_replace("\"","",$row[12]);
            $row[13]=str_replace("\"","",$row[13]);
            $row[14]=str_replace("\"","",$row[14]);
            $row[15]=str_replace("\"","",$row[15]);
            $row[16]=str_replace("\"","",$row[16]);
            $row[17]=str_replace("\"","",$row[17]);
            $row[18]=str_replace("\"","",$row[18]);
            $row[19]=str_replace("\"","",$row[19]);
            $row[20]=str_replace("\"","",$row[20]);
            $row[21]=str_replace("\"","",$row[21]);
            $row[22]=str_replace("\"","",$row[22]);
            $row[23]=str_replace("\"","",$row[23]);
            $qr = "UPDATE actt SET ACTT_IMAGE_1 = '$row[1]'
                                    ,ACTT_DECR_IMG_1 = '$row[2]'
                                    ,ACTT_IMAGE_2 = '$row[3]'
                                    ,ACTT_DECR_IMG_2 = '$row[4]'
                                    ,ACTT_IMAGE_3 = '$row[5]'
                                    ,ACTT_DECR_IMG_3 = '$row[6]'
                                    ,ACTT_IMAGE_4 = '$row[7]'
                                    ,ACTT_DECR_IMG_4 = '$row[8]'
                                    ,ACTT_IMAGE_5 = '$row[9]'
                                    ,ACTT_DECR_IMG_5 = '$row[10]'
                                    ,ACTT_ATTACHMENT_1 = '$row[11]'
                                    ,ACTT_DECR_ATT_1 = '$row[12]'
                                    ,ACTT_ATTACHMENT_2 = '$row[13]'
                                    ,ACTT_DECR_ATT_2 = '$row[14]'
                                    ,ACTT_ATTACHMENT_3 = '$row[15]'
                                    ,ACTT_DECR_ATT_3 = '$row[16]'
                                    ,ACTT_ATTACHMENT_4 = '$row[17]'
                                    ,ACTT_DECR_ATT_4 = '$row[18]'
                                    ,ACTT_ATTACHMENT_5 = '$row[19]'
                                    ,ACTT_DECR_ATT_5 = '$row[20]'
                                    ,ACTT_ATTACHMENT_6 = '$row[21]'
                                    ,ACTT_DECR_ATT_6 = '$row[22]'
                                    ,ACTT_WEBF = '$row[23]'
                            WHERE ACTT_CODE = '$row[0]'";

            $this->_db->setQuery($qr);
            if (!$this->_db->query()) {
                echo "<meta charset='UTF-8' />";
                echo "<br /><br />";
                print_r($qr);
            }
         } 
    }
    
    function update_image_1($result){
        foreach($result as $key=>$row){
            if($key == 0){
                continue;
            }
        $row[0]=str_replace("\"","",$row[0]);
        $row[1]=str_replace("\"","",$row[1]);
        $qr = "UPDATE dock SET DOCK_TBDO_CODE_LIST = '$row[1]'
                            WHERE DOCK_CODE = '$row[0]'";

            $this->_db->setQuery($qr);
            if (!$this->_db->query()) {
                echo "<meta charset='UTF-8' />";
                echo "<br /><br />";
                print_r($qr);
            }
         } 
    }     
}
